<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="docker,linux," />





  <link rel="alternate" href="/atom.xml" title="聪聪的独立博客" type="application/atom+xml" />






<meta name="description" content="前言 Docker是一个划时代的开源项目，它彻底的释放了计算虚拟化的威力，极大的提高了应用的运算效率，降低了云计算资源供应的成本！无论是应用开发者、运维人员、还是其他信息技术从业人员，都有必要认识和掌握 Docker，节约有限的时间。来自于：Docker —— 从入门到实践   根据自己的学习和记录，我就讲自己使用docker过程当中遇到的问题以及技巧记录下来，以便自己日后学习温故，同时也可以方便">
<meta name="keywords" content="docker,linux">
<meta property="og:type" content="article">
<meta property="og:title" content="linux下使用docker部署第一个Java应用">
<meta property="og:url" content="https://chencong-plan.github.io/2017/12/14/first-docker-java/index.html">
<meta property="og:site_name" content="聪聪的独立博客">
<meta property="og:description" content="前言 Docker是一个划时代的开源项目，它彻底的释放了计算虚拟化的威力，极大的提高了应用的运算效率，降低了云计算资源供应的成本！无论是应用开发者、运维人员、还是其他信息技术从业人员，都有必要认识和掌握 Docker，节约有限的时间。来自于：Docker —— 从入门到实践   根据自己的学习和记录，我就讲自己使用docker过程当中遇到的问题以及技巧记录下来，以便自己日后学习温故，同时也可以方便">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://osal57kgi.bkt.clouddn.com/wangyi_fengchao.png">
<meta property="og:updated_time" content="2017-12-20T08:35:41.805Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linux下使用docker部署第一个Java应用">
<meta name="twitter:description" content="前言 Docker是一个划时代的开源项目，它彻底的释放了计算虚拟化的威力，极大的提高了应用的运算效率，降低了云计算资源供应的成本！无论是应用开发者、运维人员、还是其他信息技术从业人员，都有必要认识和掌握 Docker，节约有限的时间。来自于：Docker —— 从入门到实践   根据自己的学习和记录，我就讲自己使用docker过程当中遇到的问题以及技巧记录下来，以便自己日后学习温故，同时也可以方便">
<meta name="twitter:image" content="http://osal57kgi.bkt.clouddn.com/wangyi_fengchao.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://chencong-plan.github.io/2017/12/14/first-docker-java/"/>





  <title>linux下使用docker部署第一个Java应用 | 聪聪的独立博客</title>
  
<style>
  .forkme{
 display: none;
 }
  @media (min-width: 768px) {
 .forkme{
 display: inline;
 }
  }
  </style>

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?042a886f72a663c61ed2f77aeae32cb7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <div class="forkme">
     <a target="_blank" href="https://github.com/chencong-plan"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/567c3a48d796e2fc06ea80409cc9dd82bf714434/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_darkblue_121621.png"></a>
    </div>
 
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">聪聪的独立博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">挥舞这本子，做个ccoder</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-messagesboard">
          <a href="/messagesBoard/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            留言板
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chencong-plan.github.io/2017/12/14/first-docker-java/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="聪聪不匆匆">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/author.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="聪聪的独立博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">linux下使用docker部署第一个Java应用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-14T10:50:08+08:00">
                2017-12-14
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于&#58;</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2017-12-20T16:35:41+08:00">
                2017-12-20
              </time>
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Linux服务器系列学习/" itemprop="url" rel="index">
                    <span itemprop="name">Linux服务器系列学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/2017/12/14/first-docker-java/#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2017/12/14/first-docker-java/" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          
             <span id="/2017/12/14/first-docker-java/" class="leancloud_visitors" data-flag-title="linux下使用docker部署第一个Java应用">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3,275
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  15
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><blockquote>
<p>Docker是一个划时代的开源项目，它彻底的释放了计算虚拟化的威力，极大的提高了应用的运算效率，降低了云计算资源供应的成本！无论是应用开发者、运维人员、还是其他信息技术从业人员，都有必要认识和掌握 Docker，节约有限的时间。<br>来自于：<a href="https://www.gitbook.com/book/yeasy/docker_practice/details" target="_blank" rel="noopener">Docker —— 从入门到实践</a> </p>
</blockquote>
<p>根据自己的学习和记录，我就讲自己使用docker过程当中遇到的问题以及技巧记录下来，以便自己日后学习温故，同时也可以方便大家共同进步。</p>
<h2 id="安装docker"><a href="#安装docker" class="headerlink" title="安装docker"></a>安装docker</h2><h3 id="安装前的检查"><a href="#安装前的检查" class="headerlink" title="安装前的检查"></a>安装前的检查</h3><ol>
<li>系统要求<ul>
<li>64位系统</li>
<li>内核版本3.10+</li>
</ul>
</li>
<li><p>检查内核版本，返回值大于3.10就行，若不是自行升级系统</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# uname -r</span><br><span class="line"><span class="number">3.10</span>.0-<span class="number">693.2</span>.2.el7.x86_64</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用sudo或者root权限的用户登入终端</p>
</li>
<li>确保yum是最新的 <code>yum update</code></li>
</ol>
<h3 id="开始安装docker"><a href="#开始安装docker" class="headerlink" title="开始安装docker"></a>开始安装docker</h3><ol>
<li><p>使用<code>yum</code>安装docker,<code>yum install -y docker</code> 安装详细过程如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# yum install -y docker</span><br><span class="line">Loaded plugins: fastestmirror</span><br><span class="line">Loading mirror speeds from cached hostfile</span><br><span class="line">Resolving Dependencies</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package docker.x86_64 <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos will be installed</span><br><span class="line">--&gt; Processing Dependency: docker-common = <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos <span class="keyword">for</span> <span class="keyword">package</span>: <span class="number">2</span>:docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64</span><br><span class="line">--&gt; Processing Dependency: docker-client = <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos <span class="keyword">for</span> <span class="keyword">package</span>: <span class="number">2</span>:docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package docker-client.x86_64 <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos will be installed</span><br><span class="line">---&gt; Package docker-common.x86_64 <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos will be installed</span><br><span class="line">--&gt; Finished Dependency Resolution</span><br><span class="line">Dependencies Resolved</span><br><span class="line">================================================================================================================================================</span><br><span class="line">Package                         Arch                     Version                                                Repository                Size</span><br><span class="line">================================================================================================================================================</span><br><span class="line">Installing:</span><br><span class="line">docker                          x86_64                   <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos                      extras                    <span class="number">15</span> M</span><br><span class="line">Installing <span class="keyword">for</span> dependencies:</span><br><span class="line">docker-client                   x86_64                   <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos                      extras                   <span class="number">3.4</span> M</span><br><span class="line">docker-common                   x86_64                   <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos                      extras                    <span class="number">80</span> k</span><br><span class="line">Transaction Summary</span><br><span class="line">================================================================================================================================================</span><br><span class="line">Install  <span class="number">1</span> Package (+<span class="number">2</span> Dependent packages)</span><br><span class="line">Total download size: <span class="number">18</span> M</span><br><span class="line">Installed size: <span class="number">63</span> M</span><br><span class="line">Downloading packages:</span><br><span class="line">(<span class="number">1</span>/<span class="number">3</span>): docker-client-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64.rpm                                                          | <span class="number">3.4</span> MB  <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>     </span><br><span class="line">(<span class="number">2</span>/<span class="number">3</span>): docker-common-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64.rpm                                                          |  <span class="number">80</span> kB  <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>     </span><br><span class="line">(<span class="number">3</span>/<span class="number">3</span>): docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64.rpm                                                                 |  <span class="number">15</span> MB  <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>     </span><br><span class="line">------------------------------------------------------------------------------------------------------------------------------------------------</span><br><span class="line">Total                                                                                                            <span class="number">12</span> MB/s |  <span class="number">18</span> MB  <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>     </span><br><span class="line">Running transaction check</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded</span><br><span class="line">Running transaction</span><br><span class="line">  Installing : <span class="number">2</span>:docker-common-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64                                                                       <span class="number">1</span>/<span class="number">3</span></span><br><span class="line">  Installing : <span class="number">2</span>:docker-client-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64                                                                       <span class="number">2</span>/<span class="number">3</span></span><br><span class="line">  Installing : <span class="number">2</span>:docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64                                                                              <span class="number">3</span>/<span class="number">3</span></span><br><span class="line">  Verifying  : <span class="number">2</span>:docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64                                                                              <span class="number">1</span>/<span class="number">3</span></span><br><span class="line">  Verifying  : <span class="number">2</span>:docker-common-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64                                                                       <span class="number">2</span>/<span class="number">3</span></span><br><span class="line">  Verifying  : <span class="number">2</span>:docker-client-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64                                                                       <span class="number">3</span>/<span class="number">3</span></span><br><span class="line">Installed:</span><br><span class="line">  docker.x86_64 <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos                                                                                               </span><br><span class="line">Dependency Installed:</span><br><span class="line">  docker-client.x86_64 <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos                 docker-common.x86_64 <span class="number">2</span>:<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos                </span><br><span class="line">Complete!</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看上面使用<code>yum</code>安装docker是否成功并且已经启动了，查看<code>docker version</code> 显示<code>docker</code>的<code>client</code>和<code>server</code>的信息如下：</p>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker version</span><br><span class="line">Client:</span><br><span class="line">Version:         <span class="number">1.12</span>.6</span><br><span class="line">API version:     <span class="number">1.24</span></span><br><span class="line">Package version: docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64</span><br><span class="line">Go version:      go1.8.3</span><br><span class="line">Git commit:      <span class="number">85</span>d7426/<span class="number">1.12</span>.6</span><br><span class="line">Built:           Tue Oct <span class="number">24</span> <span class="number">15</span>:<span class="number">40</span>:<span class="number">21</span> <span class="number">2017</span></span><br><span class="line">OS/Arch:         linux/amd64</span><br><span class="line">Server:</span><br><span class="line">Version:         <span class="number">1.12</span>.6</span><br><span class="line">API version:     <span class="number">1.24</span></span><br><span class="line">Package version: docker-<span class="number">1.12</span>.6-<span class="number">61</span>.git85d7426.el7.centos.x86_64</span><br><span class="line">Go version:      go1.8.3</span><br><span class="line">Git commit:      <span class="number">85</span>d7426/<span class="number">1.12</span>.6</span><br><span class="line">Built:           Tue Oct <span class="number">24</span> <span class="number">15</span>:<span class="number">40</span>:<span class="number">21</span> <span class="number">2017</span></span><br><span class="line">OS/Arch:         linux/amd64</span><br></pre></td></tr></table></figure>
<p>如果显示以上信息 ，说明已经成功安装<code>docker</code>，同时<code>docker</code>的<code>client</code>和<code>server</code>都已经成功运行了。</p>
<p>那么问题来了，成功运行了<code>docker</code>，但是里面没有镜像，我们如何才能够在其中运行自己的应用程序呢。下面就来介绍如何使用<a href="https://c.163.com/#/m/home/" target="_blank" rel="noopener">网易蜂巢</a>的镜像中心来安装我们的软件。</p>
<blockquote>
<p>也可以使用<code>docker</code>的<a href="https://hub.docker.com/" target="_blank" rel="noopener">镜像中心</a>,只不过在国内使用这个速度非常慢，我是用的是<code>网易镜像中心</code>，读者们也可以使用<a href="https://dev.aliyun.com/search.html" target="_blank" rel="noopener">阿里镜像中心</a>或者其他的都行。</p>
</blockquote>
<h2 id="安装镜像"><a href="#安装镜像" class="headerlink" title="安装镜像"></a>安装镜像</h2><h3 id="使用网易蜂巢镜像中心安装所需镜像"><a href="#使用网易蜂巢镜像中心安装所需镜像" class="headerlink" title="使用网易蜂巢镜像中心安装所需镜像"></a>使用网易蜂巢镜像中心安装所需镜像</h3><h4 id="安装Tomcat"><a href="#安装Tomcat" class="headerlink" title="安装Tomcat"></a>安装Tomcat</h4><ol>
<li><p>安装<code>Tomcat</code>，我们只需要在里面搜索<code>tomcat</code>就行了。其实我们平时使用的过程中就知道，如果想让<code>tomcat</code>跑起来就必须安装<code>Java</code>环境。但是在这里使用<code>docker</code>镜像安装<code>Tomcat</code>就已经包含<code>Java</code>环境了，无需另外安装。</p>
</li>
<li><p>按照上面的网址进入<code>网易蜂巢镜像中心</code>后，<strong>需要登录才会进入到入口</strong>，然后搜索<code>Tomcat</code>就行了。<br><img src="http://osal57kgi.bkt.clouddn.com/wangyi_fengchao.png" alt="image"><br>在镜像中心上搜索<code>Tomcat</code>会发现第一个<code>tomcat</code>会有一个<code>docker</code>鲸鱼的标志，这说明这个镜像资源和官方<a href="https://hub.docker.com/" target="_blank" rel="noopener">docker镜像</a>保持同步的。那我们点进去，在右边就会有一个<strong>下载地址</strong>的链接。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull hub.c.163.com/library/tomcat:latest</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>这个就是我们需要在终端上面进行<code>git</code>拉取的仓库地址。<code>docker</code>命令标志，<code>pull</code>git命令熟悉的话知道这是下载拉取的意思，<code>hub.c.163.com/library/</code>仓库地址，<code>tomcat</code>是镜像名称，<code>:</code>后面的<code>latest</code>为<code>tag</code>标签，表示当前拉取的是最新版本，如果需要其他版本的也可以在这个页面的下方寻找<code>tomcat</code>镜像的其他版本。</p>
<ol>
<li>根据上面的地址镜像下载<code>tomcat进项</code>,操作命令记录如下：<ul>
<li>下载镜像<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker pull hub.c.163.com/library/tomcat:latest</span><br><span class="line">Trying to pull repository hub.c.163.com/library/tomcat ...</span><br><span class="line">latest: Pulling from hub.c.163.com/library/tomcat</span><br><span class="line"><span class="number">9</span>af7279b9dbd: Pull complete</span><br><span class="line"><span class="number">31816</span>c948f2f: Pull complete</span><br><span class="line">c59a1cdf83d3: Pull complete</span><br><span class="line"><span class="number">232</span>c7a75d568: Pull complete</span><br><span class="line">de412d312979: Pull complete</span><br><span class="line"><span class="number">80315</span>ba34693: Pull complete</span><br><span class="line"><span class="number">5</span>d3f97bd90e8: Pull complete</span><br><span class="line">dc8dc63f6baa: Pull complete</span><br><span class="line">f6c6e2d67f03: Pull complete</span><br><span class="line"><span class="number">9123</span>b340aa92: Pull complete</span><br><span class="line"><span class="number">76</span>abaea2279d: Pull complete</span><br><span class="line"><span class="number">4476602e3346</span>: Pull complete</span><br><span class="line"><span class="number">12e1f</span>da011bd: Pull complete</span><br><span class="line">Digest: sha256:db1a8ca2fe44449d265e5505f300be6f34fc63211a5506400a0a8c24653af91f</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ol>
<p>最后面的这个<code>sha256:db1a8ca2fe44449d265e5505f300be6f34fc63211a5506400a0a8c24653af91f</code>表示改镜像在仓库当中的地址编号。</p>
<ul>
<li>查看当前docker当中的镜像 <code>docker images</code>,操作记录如下：<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker images</span><br><span class="line">REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE</span><br><span class="line">hub.c.163.com/library/tomcat   latest              <span class="number">72</span>d2be374029        <span class="number">3</span> months ago        <span class="number">292.4</span> MB</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ol>
<li>运行下载的镜像</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker run -d -p 80:8080 hub.c.163.com/library/tomcat</span><br><span class="line"><span class="number">80e53</span>db67f4bfb711ab3491f49dece1f7f9aa782e7c8d95153f36e39b6940e65</span><br><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker ps</span><br><span class="line">CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS                  NAMES</span><br><span class="line"><span class="number">80e53</span>db67f4b        hub.c.163.com/library/tomcat   <span class="string">"catalina.sh run"</span>   <span class="number">16</span> seconds ago      Up <span class="number">15</span> seconds       <span class="number">0.0</span>.0.0:<span class="number">80</span>-&gt;<span class="number">8080</span>/tcp  evil_leakey</span><br></pre></td></tr></table></figure>
<p>上面这个运行命令 <code>docker run -d -p 80:8080 hub.c.163.com/library/tomcat</code> 说明如下<br><code>docker run</code>表示运行， <code>-d</code>表示后台运行<em>docker 分为前台运行，后台运行，前台运行可以通过Ctrl+C进行停止</em> <code>-p</code>表示制定宿主机和容器之间的端口映射，在这里<code>-p 80:8080</code>表示将宿主机<code>80</code>端口映射到容器的<code>8080</code>端口。</p>
<blockquote>
<p>这里也可以使用<code>-P</code><em>大写</em>来分配端口，表示宿主机将随机分配端口映射到容器端口，容器端口不变。操作如下：</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker run -d -P hub.c.163.com/library/tomcat</span><br><span class="line"><span class="number">965</span>a99cdb70730716aa466ddefe28c55fb7161e9030f8d42d0055711b26c7b25</span><br><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker ps</span><br><span class="line">CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS                     NAMES</span><br><span class="line"><span class="number">965</span>a99cdb707        hub.c.163.com/library/tomcat   <span class="string">"catalina.sh run"</span>   <span class="number">4</span> seconds ago       Up <span class="number">3</span> seconds        <span class="number">0.0</span>.0.0:<span class="number">32768</span>-&gt;<span class="number">8080</span>/tcp   kickass_swirles</span><br><span class="line"><span class="number">80e53</span>db67f4b        hub.c.163.com/library/tomcat   <span class="string">"catalina.sh run"</span>   <span class="number">5</span> minutes ago       Up <span class="number">5</span> minutes        <span class="number">0.0</span>.0.0:<span class="number">80</span>-&gt;<span class="number">8080</span>/tcp      evil_leakey</span><br></pre></td></tr></table></figure>
<p>上面通过命令<code>docker ps</code>查看当前正在运行的容器，可以看出 <code>Tomcat</code>正在运行的有两个，而且两个的端口号还不一样，<code>80</code>是我们上面<code>-p</code>指定的，<code>32768</code>是通过<code>-P</code>随机分配的。而且<code>localhost:80</code>和<code>localhost:32768</code>都是可以访问到<code>tomcat</code>的首页的。</p>
<ol>
<li>暂停容器</li>
</ol>
<p>在上面提到了使用命令<code>docker ps</code>可以查看当前正在运行的容器。那么我们可以使用 <code>docker stop CONTAINER ID</code>进行停止正在运行的容器，比如上面的<code>80</code>端口的容器的<code>CONTAINER ID</code>是<code>80e53db67f4b</code>,现在想将其停止就可以使用<code>docker stop</code>命令了，而且这个<code>CONTAINER ID</code>还可以简写，操作记录如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker stop 80</span><br><span class="line"><span class="number">80</span></span><br><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker ps</span><br><span class="line">CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS                     NAMES</span><br><span class="line"><span class="number">965</span>a99cdb707        hub.c.163.com/library/tomcat   <span class="string">"catalina.sh run"</span>   <span class="number">6</span> minutes ago       Up <span class="number">6</span> minutes        <span class="number">0.0</span>.0.0:<span class="number">32768</span>-&gt;<span class="number">8080</span>/tcp   kickass_swirles</span><br></pre></td></tr></table></figure>
<p>通过<code>docker ps</code>可以很清楚的看到当前只剩下端口号为<code>32768</code>的正在运行。同时地址栏当中也已经无法使用<code>localhost:80</code>进行访问<code>Tomcat</code>的首页了。</p>
<p>到现在为止，我们就已经在<code>docker</code>当中安装好了我们的第一个应用， 并且成功运行了。有了<code>Tomcat</code>我们就可以运行自己的Web应用了，那么问题来了，数据库怎么办呢？下面我就来说说怎么安装数据库吧，其实答题的操作都差不多，镜像中心找到<code>MySQL</code>的拉取地址，然后终端运行下载镜像，运行，映射端口。</p>
<h4 id="安装MySQL"><a href="#安装MySQL" class="headerlink" title="安装MySQL"></a>安装MySQL</h4><ol>
<li><p>同样进入网易蜂巢镜像中心，搜索<code>MySQL</code>，找到其下载地址。<code>docker pull hub.c.163.com/library/mysql:latest</code></p>
</li>
<li><p>进入<code>linux</code>终端，输入上面下载地址的命令，详细过程如下：</p>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker pull hub.c.163.com/library/mysql:latest</span><br><span class="line">Trying to pull repository hub.c.163.com/library/mysql ...</span><br><span class="line">latest: Pulling from hub.c.163.com/library/mysql</span><br><span class="line"><span class="number">42</span>cb69312da9: Pull complete</span><br><span class="line">e2cf5467c4b5: Pull complete</span><br><span class="line"><span class="number">871</span>ec0232f66: Pull complete</span><br><span class="line"><span class="number">3</span>c0ae7ec690d: Pull complete</span><br><span class="line">d39b43089b70: Pull complete</span><br><span class="line">aa0e7cb4b67c: Pull complete</span><br><span class="line"><span class="number">738</span>db9902d06: Pull complete</span><br><span class="line">ae333863ac05: Pull complete</span><br><span class="line"><span class="number">6</span>d014992204a: Pull complete</span><br><span class="line"><span class="number">09</span>aeca0c9a82: Pull complete</span><br><span class="line"><span class="number">0162083</span>b2de0: Pull complete</span><br><span class="line">Digest: sha256:b2bce1a792237ac5df78877d583f34b09ab023a77130921a6bcce67ce2d24ff0</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>docker run</code>命令运行下载好的<code>MySQL</code>镜像。可能运行<code>MySQL</code>和<code>Tomcat</code>不太一样，在这里我们不止需要制定映射端口，还需要为<code>MySQL</code>指定访问的用户名和密码。</p>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker run --name root -e MYSQL_ROOT_PASSWORD=123456 -d -p 3306:3306 hub.c.163.com/library/mysql</span><br><span class="line"><span class="number">0e00273</span>b42da6c30ca21798c0fed807cc91d758b08087324668338172b6eb62d</span><br></pre></td></tr></table></figure>
<p>如上面命令所示，用户名为<code>root</code>，密码为<code>123456</code>,我们可以用<code>navicate</code>测试是否连接上。<br>上面命令参数的说明详细见网易蜂巢镜像文档当中。<a href="https://c.163.com/hub#/m/repository/?repoId=2955" target="_blank" rel="noopener">详细说明</a> 关于如何创建用户名，如何跨容器连接MySQL等</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">How to use <span class="keyword">this</span> image</span><br><span class="line"></span><br><span class="line">Start a mysql server instance</span><br><span class="line"></span><br><span class="line">Starting a MySQL instance is simple:</span><br><span class="line"></span><br><span class="line">$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag</span><br><span class="line">... where some-mysql is the name you want to assign to your container, my-secret-pw is the password to be set <span class="keyword">for</span> the MySQL root user and tag is the tag specifying the MySQL version you want. See the list above <span class="keyword">for</span> relevant tags.</span><br></pre></td></tr></table></figure>
<h3 id="使用镜像"><a href="#使用镜像" class="headerlink" title="使用镜像"></a>使用镜像</h3><h4 id="进入容器"><a href="#进入容器" class="headerlink" title="进入容器"></a>进入容器</h4><p>在刚刚我们创建了<code>Tomcat</code>和<code>MySQL</code>的容器，那么如何进入到这些正在运行的容器当中呢。可以使用命令<code>docker ps</code>查看正在运行的容器。然后使用命令<code>docker exit -it [NAMES] bash</code> 指定需要进入的具体容器是哪一个。这个参数<code>-it</code>表示使用<strong>交互模式</strong>运行，同时返回一个可以操作的终端，这里的<code>NAMES</code>就是<code>docker ps</code>查看到的容器运行时候最后一个名字。操作记录如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker ps</span><br><span class="line">CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES</span><br><span class="line"><span class="number">5f</span>ea4d975b62        hub.c.163.com/library/tomcat   <span class="string">"catalina.sh run"</span>        <span class="number">16</span> seconds ago      Up <span class="number">15</span> seconds       <span class="number">0.0</span>.0.0:<span class="number">8080</span>-&gt;<span class="number">8080</span>/tcp   hungry_noether</span><br><span class="line">ed96dabaff1f        hub.c.163.com/library/mysql    <span class="string">"docker-entrypoint.sh"</span>   <span class="number">7</span> minutes ago       Up <span class="number">7</span> minutes        <span class="number">0.0</span>.0.0:<span class="number">3306</span>-&gt;<span class="number">3306</span>/tcp   root</span><br><span class="line"><span class="number">8</span>c93f7088b22        my-nginx                       <span class="string">"nginx -g 'daemon off"</span>   <span class="number">46</span> minutes ago      Up <span class="number">46</span> minutes       <span class="number">0.0</span>.0.0:<span class="number">80</span>-&gt;<span class="number">80</span>/tcp       adoring_hopper</span><br></pre></td></tr></table></figure>
<p>上面很清楚的显示<code>MySQL</code>的<code>NAMES</code>是<code>root</code>，那么我们就可以使用命令<code>docker exec -it root bash</code>来进入容器，记录如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it root bash</span><br></pre></td></tr></table></figure>
<p>但是此时只是进入了容器，还需要进入<code>MySQL</code>怎么操作呢，跟我们平常在<code>Linux</code>上一样操作，<code>mysql -uroot -p</code>操作记录如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker ps</span><br><span class="line">CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                    NAMES</span><br><span class="line">b7ae64383c2c        tomcat:mydocs2                <span class="string">"catalina.sh run"</span>        <span class="number">6</span> days ago          Up <span class="number">6</span> days           <span class="number">0.0</span>.0.0:<span class="number">80</span>-&gt;<span class="number">8080</span>/tcp     prickly_borg</span><br><span class="line"><span class="number">87680</span>cea7eb4        hub.c.163.com/library/mysql   <span class="string">"docker-entrypoint.sh"</span>   <span class="number">6</span> days ago          Up <span class="number">6</span> days           <span class="number">0.0</span>.0.0:<span class="number">3306</span>-&gt;<span class="number">3306</span>/tcp   root</span><br><span class="line">[root@iZj1fkye8uu7o0Z ~]# docker exec -it root bash</span><br><span class="line">root@87680cea7eb4:/# mysql -uroot -p                                                                                                                                                          </span><br><span class="line">Enter password: </span><br><span class="line">Welcome to the MySQL monitor.  Commands end with ; or \g.</span><br><span class="line">Your MySQL connection id is <span class="number">108</span></span><br><span class="line">Server version: <span class="number">5.7</span>.18 <span class="function">MySQL Community <span class="title">Server</span> <span class="params">(GPL)</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Copyright</span> <span class="params">(c)</span> 2000, 2017, Oracle and/or its affiliates. All rights reserved.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">Oracle is a registered trademark of Oracle Corporation and/or its</span></span><br><span class="line"><span class="function">affiliates. Other names may be trademarks of their respective</span></span><br><span class="line"><span class="function">owners.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">Type 'help</span>;<span class="string">' or '</span>\h<span class="string">' for help. Type '</span>\c<span class="string">' to clear the current input statement.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">mysql&gt;</span></span><br></pre></td></tr></table></figure>
<p>现在就可以愉快的玩耍了。</p>
<h4 id="退出容器"><a href="#退出容器" class="headerlink" title="退出容器"></a>退出容器</h4><ol>
<li>如果使用上面<code>docker exec -it NAMES bash</code>方式进入容器，可以直接使用<code>exit</code>，退出容器，而不会将其停止。</li>
</ol>
<h2 id="后记"><a href="#后记" class="headerlink" title="后记"></a>后记</h2><p>通过学习<code>linux</code>上部署<code>docker</code>，平时需要独立安装的各种环境变得简单，同时也可以自行通过<code>Dockerfile</code>文件来<code>build</code>自己的镜像，然后<code>pash</code>到仓库，或者厂商的镜像中心当中，以便日后再用，都是非常方便的。同时也可以在一台宿主机当中部署多个<code>docker</code>，实现集群服务也是可以的。当然我们也可以使用<code>Web</code>端的工具来管理<code>docker</code>,相应的工具名称大家可以自行搜索使用。</p>
<h2 id="联系"><a href="#联系" class="headerlink" title="联系"></a>联系</h2><p><a href="https://ccoder.cc/" target="_blank" rel="noopener">聪聪</a>的独立博客 ，一个喜欢技术，喜欢钻研的95后。如果你看到这篇文章，千里之外，我在等你联系。</p>
<ul>
<li><a href="https://ccoder.cc/" target="_blank" rel="noopener">Blog@ccoder’s blog</a></li>
<li><a href="http://blog.csdn.net/chencong3139" target="_blank" rel="noopener">CSDN@ccoder</a></li>
<li><a href="https://github.com/chencong-plan" target="_blank" rel="noopener">Github@ccoder</a></li>
<li><a href="mailto:admin@ccoder.top" target="_blank" rel="noopener">Email@ccoder</a> <em>or</em> <a href="mailto:chencong3139@gmail.com" target="_blank" rel="noopener">Gmail@ccoder</a></li>
</ul>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat_pay.png" alt="聪聪不匆匆 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/ali_pay.png" alt="聪聪不匆匆 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    聪聪不匆匆
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://chencong-plan.github.io/2017/12/14/first-docker-java/" title="linux下使用docker部署第一个Java应用">https://chencong-plan.github.io/2017/12/14/first-docker-java/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/docker/" rel="tag"><i class="fa fa-tag"></i> docker</a>
          
            <a href="/tags/linux/" rel="tag"><i class="fa fa-tag"></i> linux</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/12/08/about-me/" rel="next" title="关于我">
                <i class="fa fa-chevron-left"></i> 关于我
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/12/20/selection-sort/" rel="prev" title="算法篇——选择排序SelectionSort">
                算法篇——选择排序SelectionSort <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/author.png"
                alt="聪聪不匆匆" />
            
              <p class="site-author-name" itemprop="name">聪聪不匆匆</p>
              <p class="site-description motion-element" itemprop="description">hello，every body!~</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/chencong-plan" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-globe"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:1042738887@qq.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-globe"></i>E-Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://blog.csdn.net/chencong3139" target="_blank" title="CSDN">
                    
                      <i class="fa fa-fw fa-globe"></i>CSDN</a>
                </span>
              
            
          </div>

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://blog.csdn.net/chencong3139" title="CSDN" target="_blank">CSDN</a>
                  </li>
                
              </ul>
            </div>
          

          <div id="music163player">
   <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=496620009&auto=0&height=66"></iframe>
</div>

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text"><a href="#&#x524D;&#x8A00;" class="headerlink" title="&#x524D;&#x8A00;"></a>&#x524D;&#x8A00;</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装docker"><span class="nav-number">2.</span> <span class="nav-text"><a href="#&#x5B89;&#x88C5;docker" class="headerlink" title="&#x5B89;&#x88C5;docker"></a>&#x5B89;&#x88C5;docker</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装前的检查"><span class="nav-number">2.1.</span> <span class="nav-text"><a href="#&#x5B89;&#x88C5;&#x524D;&#x7684;&#x68C0;&#x67E5;" class="headerlink" title="&#x5B89;&#x88C5;&#x524D;&#x7684;&#x68C0;&#x67E5;"></a>&#x5B89;&#x88C5;&#x524D;&#x7684;&#x68C0;&#x67E5;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#开始安装docker"><span class="nav-number">2.2.</span> <span class="nav-text"><a href="#&#x5F00;&#x59CB;&#x5B89;&#x88C5;docker" class="headerlink" title="&#x5F00;&#x59CB;&#x5B89;&#x88C5;docker"></a>&#x5F00;&#x59CB;&#x5B89;&#x88C5;docker</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装镜像"><span class="nav-number">3.</span> <span class="nav-text"><a href="#&#x5B89;&#x88C5;&#x955C;&#x50CF;" class="headerlink" title="&#x5B89;&#x88C5;&#x955C;&#x50CF;"></a>&#x5B89;&#x88C5;&#x955C;&#x50CF;</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#使用网易蜂巢镜像中心安装所需镜像"><span class="nav-number">3.1.</span> <span class="nav-text"><a href="#&#x4F7F;&#x7528;&#x7F51;&#x6613;&#x8702;&#x5DE2;&#x955C;&#x50CF;&#x4E2D;&#x5FC3;&#x5B89;&#x88C5;&#x6240;&#x9700;&#x955C;&#x50CF;" class="headerlink" title="&#x4F7F;&#x7528;&#x7F51;&#x6613;&#x8702;&#x5DE2;&#x955C;&#x50CF;&#x4E2D;&#x5FC3;&#x5B89;&#x88C5;&#x6240;&#x9700;&#x955C;&#x50CF;"></a>&#x4F7F;&#x7528;&#x7F51;&#x6613;&#x8702;&#x5DE2;&#x955C;&#x50CF;&#x4E2D;&#x5FC3;&#x5B89;&#x88C5;&#x6240;&#x9700;&#x955C;&#x50CF;</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装Tomcat"><span class="nav-number">3.1.1.</span> <span class="nav-text"><a href="#&#x5B89;&#x88C5;Tomcat" class="headerlink" title="&#x5B89;&#x88C5;Tomcat"></a>&#x5B89;&#x88C5;Tomcat</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装MySQL"><span class="nav-number">3.1.2.</span> <span class="nav-text"><a href="#&#x5B89;&#x88C5;MySQL" class="headerlink" title="&#x5B89;&#x88C5;MySQL"></a>&#x5B89;&#x88C5;MySQL</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用镜像"><span class="nav-number">3.2.</span> <span class="nav-text"><a href="#&#x4F7F;&#x7528;&#x955C;&#x50CF;" class="headerlink" title="&#x4F7F;&#x7528;&#x955C;&#x50CF;"></a>&#x4F7F;&#x7528;&#x955C;&#x50CF;</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#进入容器"><span class="nav-number">3.2.1.</span> <span class="nav-text"><a href="#&#x8FDB;&#x5165;&#x5BB9;&#x5668;" class="headerlink" title="&#x8FDB;&#x5165;&#x5BB9;&#x5668;"></a>&#x8FDB;&#x5165;&#x5BB9;&#x5668;</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#退出容器"><span class="nav-number">3.2.2.</span> <span class="nav-text"><a href="#&#x9000;&#x51FA;&#x5BB9;&#x5668;" class="headerlink" title="&#x9000;&#x51FA;&#x5BB9;&#x5668;"></a>&#x9000;&#x51FA;&#x5BB9;&#x5668;</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#后记"><span class="nav-number">4.</span> <span class="nav-text"><a href="#&#x540E;&#x8BB0;" class="headerlink" title="&#x540E;&#x8BB0;"></a>&#x540E;&#x8BB0;</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#联系"><span class="nav-number">5.</span> <span class="nav-text"><a href="#&#x8054;&#x7CFB;" class="headerlink" title="&#x8054;&#x7CFB;"></a>&#x8054;&#x7CFB;</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">聪聪不匆匆</span>

<!--以下3行为一条竖线和Coding Page-->
  <div class="powered-by">  
  </div>
  <span>Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a></span>
</div>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">17.2k</span>
  
</div>









        







        
      </div>
    </footer>

    

    
      <div id="needsharebutton-float">
        <span class="btn">
          <i class="fa fa-share-alt" aria-hidden="true"></i>
        </span>
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cytb0COPK';
      var conf = 'f4ec61439cc0436460d4314634c8eb78';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  









  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("ydueKuP9DBwlcJdmt9zWF1VV-gzGzoHsz", "QfeANi9TLulHoKgHq6V0XJ0U");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
    
      flOptions = {};
      
          flOptions.iconStyle = "box";
      
          flOptions.boxForm = "horizontal";
      
          flOptions.position = "middleRight";
      
          flOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-float', flOptions);
    
  </script>

  

  

  

  


  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
</body>
</html>
